<?php

namespace app\admin\controller\dim;

use app\admin\model\DimArea;
use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="dim_area")
 */
class Area extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\DimArea();
        
    }

    /**
     * 获取列表
     *
     */
    public function getList()
    {

        $pid = input('pid', DimArea::DEFAULT_ID);
        $name = input('name', '');

        $conditions = array();
        empty($pid) ?: $conditions[] = array('pid', '=', $pid);
        empty($name) ?: $conditions[] = array('name', 'like', "%{$name}%");

        try{
            $result = $this->model
                ->where($conditions)
                ->order('sort', 'asc')
                ->select()->toArray();

            _return(0, 'success', $result);
        }catch (\Exception $e){
            _return(-1,  'error: ' .$e->getMessage());
        }
    }
}